#include<iostream>
#include<queue>
using namespace std;
class Haffman
{
	int tree[100] = { 0 };
	int size = 0;
public:
	void Push(int x = 0)
	{
		tree[size++] = x;
	}
	int fun(int root = 0, int level = 0)
	{
		int ct = 0;
		int m = 1;
		int n = 1;
		while (root < size)
		{
			ct = ct + level * tree[root];
			root++;
			if (root == m)
			{
				m = m+n*2;
				n *= 2;
				level++;
			}
		}
		return  ct;
	}
};
int main()
{
	Haffman tree;
	priority_queue<int> q;
	int n;
	cin >> n;
	int h = 1;
	int ct = 1;
	while (ct <= n)
	{
		ct = ct * 2;
		h++;
	}
	int presize = ct / 2;
	int size = ct - 1 + (n - presize)*2;
	int arr[100] = { 0 };
	int i = 0;
	for (i; i < n; i++)
	{
		int m;
		cin >> m;
		q.push(m);
	}
	for (i = n-1; i >=0; i--)
	{
		arr[i] = q.top();
		q.pop();
	}
	for (i = size-1 ; i >= 0; i--)
	{
		tree.Push(arr[i]);
	}
	cout << tree.fun();
}